﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Fierce.Utility.Helper;
using Fierce.Entity.Basic;
using Fierce.Core.Aop;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.AspNetCore.Authorization;
using Fierce.Cache;
using System.Security.Claims;

namespace Fierce.MvcExtend.Controllers
{
    [Authorize]
    public abstract class WorkController : Controller
    {
        public string SignScheme
        {
            get { return "work"; }
        }

        public bool IsAuthenticated
        {
            get { return HttpContext.User.Identity.IsAuthenticated; }
        }

        public string UserID
        {
            get { return HttpContext.User.GetUserID(); }
        }

        public string UserName
        {
            get { return HttpContext.User.GetUserName(); }
        }

        public bool IsSuper
        {
            get { return HttpContext.User.GetIsSuper(); }
        }

        public BasicUser UserData
        {
            get { return ServiceFactory.BasicUser.Get(UserID); }
        }

        public BasicMenu Menu { get; set; }

        private void PageMenuInit()
        {
            string menuid = Request.Query["_menuid"];

            if (!string.IsNullOrEmpty(menuid))
            {
                Menu = ServiceFactory.BasicMenu.Get(menuid);
            }
        }

        public override void OnActionExecuting(ActionExecutingContext context)
        {
            if (IsAuthenticated)
            {
                PageMenuInit();
            }

            ViewBag.Work = this;

            base.OnActionExecuting(context);
        }
    }
}